package com.wanho.java157.crm.personalOffice.task.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanho.java157.crm.personalOffice.task.mapper.IndividualTaskMapper;
import com.wanho.java157.crm.personalOffice.task.po.IndividualTask;
import com.wanho.java157.crm.personalOffice.task.service.IndividualTaskService;
import com.wanho.java157.crm.systemSettings.manage.po.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndividualTaskServiceImpl implements IndividualTaskService {
    @Autowired
    private IndividualTaskMapper individualTaskMapper ;
    @Override
    public PageInfo<IndividualTask> listPage(int page,int size,Integer employeeId) {
        PageHelper.startPage(page,size) ;
        List<IndividualTask> individualTasks = individualTaskMapper.selectIndividualTaskByEmployeeId(employeeId);
        return new PageInfo<>(individualTasks);
    }

    @Override
    public boolean addTask(IndividualTask task) {
        //模拟当前登录用户
        Employee operator = new Employee();
        operator.setEmployeeId(4);
        task.setOperator(operator);
        //1. 插入任务表【需要返回自增长主键】
        individualTaskMapper.insertTask(task) ;
        //2. 插入关系表
        individualTaskMapper.insertTaskUserRelationsBatch(task) ;
        return true;
    }
}
